@extends('layouts.header')
@section('style')
    .down-line {
    /* text-decoration:underline; */
    /* padding-bottom:0px;  */
    border-bottom: 1px solid #00f
    }
@endsection
@section('title','结果查看')
@section('content')
<article class="page-container">
    <div class="cl pd-5 bg-1 bk-gray">
        <a href="/{{config('constant.name_admin')}}/exportReport/origin?id={{$sample_info_data->id}}" target="_blank" class="btn btn-primary radius" ><i class="Hui-iconfont">&#xe640;</i>原始记录</a>
        <a class="btn btn-primary radius r" href="javascript:location.reload();" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </div>
    <div class="mb-15">
        <div class="f-l col-xs-4">
            <b>　条形码：</b><span style="color:red;font-size:18px;">{{ $sample_info_data->bar_code }}</span><br>
            @if(DB::table('setting')->where('id', '1')->value('enable_tool_ID'))
                <b>工器具ID：</b><span style="color:red;">{{ $sample_info_data->gqj_ID }}</span><br>
            @endif
            <b>样品名称：</b>{{ $gaiyao_data->tool_name }}<br>
            <b>检验标准：</b>{{ $gaiyao_data->std_num }}<br>
            <b>额定电压：</b>{{ $gaiyao_data->voltage }}<br>
            <b>　　分类：</b>{{ $gaiyao_data->class }}<br>
            <b>样品状态：</b>{{ $sample_info_data->sample_status }}<br>
        </div>
        <div class="f-l col-xs-4">
            <b>　自编号：</b>{{ $sample_info_data->self_num }}<br>
            <b>生产厂家：</b>{{ $sample_info_data->manufacturer }}<br>
            <b>生产日期：</b>{{ $sample_info_data->production_date }}<br>
            <b>规格型号：</b>{{ $sample_info_data->guige_xinghao }}<br>
            <b>　　商标：</b>{{ $sample_info_data->brand }}<br>
            <b>使用周期：</b>{{ $cycle }}年<br>
            <b>　　备注：</b>{{ $sample_info_data->remark }}<br>
        </div>
        <div class="f-l col-xs-4">
            <b>　　状态：</b> <b class="c-red">{{ $sample_info_data->status0 ?: '/' }}</b> <br>
            <b>　审核人：</b> <b class="c-red">{{ $sample_info_data->audit_man ?: '/'  }}</b> <br>
            <b>审核日期：</b> <b class="c-red">{{ $sample_info_data->check_time ?: '/' }}</b> <br>
            <b>　批准人：</b> <b class="c-red">{{ $sample_info_data->approve_man ?: '/' }}</b> <br>
            <b>批准日期：</b> <b class="c-red">{{ $sample_info_data->approve_end ?: '/' }}</b> <br>
            <b>到期时间：</b> <b class="c-red">{{ $sample_info_data->next_time ?: '/' }}</b> <br>
        </div>
        <div style="clear:both"></div>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-10 mb-10">
            <span class="l">
                <b>条形码：</b><input type="text" class="input-text" value="" placeholder="后三位" id="bar-code" style="width:60px">
            </span>
        <span class="l ml-10">
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_jump()">跳转</a>
            </span>
        <span class="r mr-10">
                @if ($sample_id_next)
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_next }})">下一个</a>
            @else
                <a class="btn radius disabled" href="javascript:;">下一个</a>
            @endif
            </span>
        <span class="r mr-20">
                @if ($sample_id_pre)
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_pre }})">上一个</a>
            @else
                <a class="btn radius disabled" href="javascript:;">上一个</a>
            @endif
            </span>
    </div>

    <ul id="Huifold" class="Huifold">
        @foreach ($items_data as $val){{-- 第一层循环 --}}
        {{-- <form action="" method="post"> --}}
        <li class="item">
            <h4>
                {{ $val->name }}
                @if ($val->res === 1)
                    <span class="badge badge-success radius">符合</span>
                @elseif ($val->res === 0)
                    <span class="badge badge-danger radius">不符合</span>
                @endif
                <b>+</b>
            </h4>
            <div class="info">
                <b style="color:blue">主检人员</b>&emsp;
                <span class="down-line">{{ $val->realname }}</span>
                <b style="color:blue">&emsp; 试验日期</b>&emsp;
                <span class="down-line">{{ $val->utime?date("Y年m月d日",strtotime($val->utime)):'　　　　　　　　' }}</span>
                <hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>
                <b style="color:blue">检验标准</b>&emsp;
                @php
                    $yaoqiu = DB::table('a_std_tool_item_rel')->where([
                        ['std_id','=',$gaiyao_data->std_id],
                        ['tool_id','=',$gaiyao_data->tool_id],
                        ['testitem_id','=',$val->item_id]
                    ])->value('jishu_yaoqiu');

                    $key_condition = DB::table('a_condition_key')->select('id','key','unit')->where([
                        ['std_id','=',$gaiyao_data->std_id],
                        ['tool_id','=',$gaiyao_data->tool_id],
                        ['item_id','=',$val->item_id]
                    ])->orderBy('sort')->get();

                    foreach ($key_condition as $k => $v){ // 第二层循环
                        $val_condition = DB::table('a_condition')->where('condition_key_id','=',$v->id)->whereIn('vol_class_id',[$gaiyao_data->vol_id,$gaiyao_data->class_id])->pluck('val')->toArray();
                        $val_condition = implode($val_condition,' / ');
                        echo "<b>{$v->key}：</b>$val_condition{$v->unit}&emsp;";
                    }

                    echo "<b>要求：</b>$yaoqiu";
                    echo "<hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>";
                @endphp

                <input type="hidden" name="item_id" value="{{ $val->id }}">
                <b style="color:blue">原始记录</b>&emsp;

                <div style="display: inline;" class="@if($val->item_id===61) hidden @endif">
                    <b>天气：</b><span class="down-line">{{$val->wea || $val->wea=='0' ? $val->wea:'　'}}</span>&emsp;
                    <b>大气压力：</b><span class="down-line">{{$val->pressure || $val->pressure=='0' ? $val->pressure:'　'}}kPa</span>&emsp;
                    <b>环境温度：</b><span class="down-line">{{$val->temp || $val->temp=='0' ? $val->temp:'　'}}℃</span>&emsp;
                    <b>相对湿度：</b><span class="down-line">{{$val->hum || $val->hum=='0' ? $val->hum:'　'}}%</span>&emsp;
                </div>
                @php
                    $key_data = DB::table('a_testdata_key as a')
                        ->leftJoin('a_std_tool_item_rel as b','a.std_tool_item_rel_id','=','b.id')
                        ->select('a.id','a.data_key','a.data_unit')
                        ->where([
                            ['b.std_id','=',$gaiyao_data->std_id],
                            ['b.tool_id','=',$gaiyao_data->tool_id],
                            ['b.testitem_id','=',$val->item_id]
                        ])->orderBy('a.sort')->get();
                    if ($key_data->isNotEmpty()) {
                        echo '<br><b>　　　　</b>&emsp; ';
                    }
                    foreach ($key_data as $k => $v) {
                        $input_data = DB::table('a_input_data')->where([
                                ['sample_info_id','=',$sample_info_data->id],
                                ['testdata_key_id','=',$v->id]
                            ])->first();
                        if ($input_data) {
                            $input_data_v = ($input_data->val || $input_data->val=="0") ? $input_data->val : "　";
                            echo "<span><b>{$v->data_key}：</b><span class='down-line'>{$input_data_v}{$v->data_unit} </span> &nbsp;<i class='btn btn-primary radius size-MINI' onclick=\"getHistory('{$v->data_key}','{$input_data->id}')\">历史记录</i></span> &nbsp;&nbsp;&nbsp;";
                        }
                    }
                @endphp
                <hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>
                <div class="@if($val->item_id===61) hidden @endif">
                    <b style="color:blue">设备列表</b>
                    <div class="mb-10  ml-30">
                        <table class="table table-border table-bordered table-hover table-bg table-responsive" >
                            <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>编号</th>
                                    <th class="text-c">有效期</th>
                                </tr>
                            </thead>
                            <tbody>
                            @if($val->station_ids)
                                @php
                                    $staIds = explode(',',$val->station_ids);
                                    $stations = DB::table('a_station')->whereIn('id',$staIds)->get();
                                @endphp
                                @foreach($stations as $item)
                                    <tr>
                                        <td>{{$item->name}}</td>
                                        <td>{{$item->dev_num}}</td>
                                        <td class="text-c">{{$item->trace_exp_date ? $item->trace_exp_date : '/'}}</td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
                <br><b>　　　　</b>&emsp; <b>备注/不符合现象描述：</b><span class="down-line">{{ $val->remark }}</span>
                {{-- <select name="res">
                    <option value="1">符合</option>
                    <option value="0">不符合</option>
                </select> --}}
                {{-- @csrf --}}
                {{-- <input type="submit" value="保存"> --}}
            </div>
        </li>
        {{-- </form> --}}
        @endforeach
    </ul>

</article>
<script type="text/javascript" src="/admin/lib/jquery/FileSaver.js"></script>
<script type="text/javascript" src="/admin/lib/jquery/jquery.wordexport.js"></script>
<script>
    $(function () {
        $("#Huifold").Huifold({
            titCell: '.item h4',
            mainCell: '.item .info',
            type: 3,
            trigger: 'click',
            className: "selected",
            // speed:"fast",//"slow" | "normal" | "fast"
            speed: 0
        });

        //默认展开第一个
        // $("#Huifold li").first().find('h4').trigger("click");
        $("#Huifold li").find('h4').trigger("click");

    });

    /*查看上一个 下一个样品*/
    function goto_pre_next(id) {
        window.location.href = "/{{config('constant.name_admin')}}/itemData/view?id=" + id;
    }

    function goto_jump() {
        let barCode = $('#bar-code').val(),
            bw = '{{substr($sample_info_data->bar_code,0,-3)}}';
        if (!barCode) {
            layer.msg('请先输入后三位号码！');
            return false;
        }
        window.location.href = "/{{config('constant.name_admin')}}/itemData/view?barCode=" + bw + barCode;
    }
     /*查看历史记录*/
    function getHistory(data_key,input_id){
        ajax('get', 'inputHistory', {'input_id':input_id}, getHistoryBak,0);
        function getHistoryBak(res) {
            // console.log(res);
            if(res.length == 0){
                layer.msg('暂无数据！');
                return false;
            }
            
            let content = 
                    '<div class="page-container">'+
                        '<table class="table table-border table-bordered table-hover table-bg table-responsive" >'+
                            '<thead>'+
                                '<tr>'+
                                    '<th>操作员</th>'+
                                    '<th>值</th>'+
                                    '<th>修改时间</th>'+
                                    '<th>ip</th>'+
                                '</tr>'+
                            '</thead>'+
                            '<tbody>';
            for(let i in res){
                content +=      '<tr>'+
                                    '<td>'+res[i].manager_realname+'</td>'+
                                    '<td>'+res[i].val+'</td>'+
                                    '<td>'+res[i].ctime+'</td>'+
                                    '<td>'+res[i].ip+'</td>'+
                                '</tr>';    
            }
                content +=  '</tbody>'+
                    '</div>';
            layer.open({
                type: 1,
                area: ['400px', '300px'],
                fix: false, //不固定
                // maxmin: true,
                shade:0.4,
                title: data_key+' 历史记录',
                content: content,
                anim: 0,
                isOutAnim: false,//关闭层时的过度动画
                resize: true,//是否允许右下角拖动来拉伸
                moveOut: true,//是否允许拖拽到窗口外
            });
        }
    }
</script>
@endsection